package com.union.core.organization.service;

import java.util.List;

import org.apache.log4j.Logger;

import com.union.core.organization.dao.PersonnelDao;
import com.union.core.organization.dao.impl.PersonnelDaoImpl;
import com.union.core.organization.model.Personnel;
import com.union.core.sys.dao.impl.SysManagerDaoImpl;

public class PersonnelService{
	
	private PersonnelDao personnelDaoImpl;
	private static Logger log = Logger.getLogger(PersonnelService.class.getName());
	private SysManagerDaoImpl sysManagerDaoImpl;
	public PersonnelService(){
		personnelDaoImpl = new PersonnelDaoImpl();
		sysManagerDaoImpl = new SysManagerDaoImpl();
	}
	
	/**
	 * 
	 * @param personnel_id
	 * @param personnel_name
	 * @param personnel_age
	 * @param personnel_sex
	 * @param personnel_position
	 * @param organization_name
	 * @param paramName
	 * @param paramValue
	 * @param orderByName
	 * @param start
	 * @param pageSize
	 * @return
	 */
	public List<Personnel> queryList(int personnel_id,String personnel_name,String birthday,String personnel_sex,String personnel_position,
			String organization_name, String department, String paramName, String paramValue, String orderByName,int start,int pageSize,int organization_id,String getChildLst){
		List<Personnel> personnelList = personnelDaoImpl.queryList(personnel_id, personnel_name, birthday, 
				personnel_sex, personnel_position, organization_name, department,paramName, paramValue, orderByName, start, pageSize, organization_id,getChildLst);
		log.info("PLAT 查询人员信息：personnel_id="+personnel_id+",personnel_name="+personnel_name+",birthday="+birthday
				+ ",personnel_sex="+personnel_sex+",personnel_position="+personnel_position+",organization_name="+organization_name+",department="+department
				+ ",paramName="+paramName+",paramValue="+paramValue+",orderByName="+orderByName
				+ ",start="+start+",pageSize="+pageSize);
		
		return personnelList;
	}
	
	/**
	 * 
	 * @param personnel_id
	 * @param personnel_name
	 * @param personnel_age
	 * @param personnel_sex
	 * @param personnel_position
	 * @param organization_name
	 * @param paramName
	 * @param paramValue
	 * @param orderByName
	 * @return
	 */
		
	public int ListCount(int personnel_id,String personnel_name,String birthday,String personnel_sex,String personnel_position,
			String organization_name, String department, String paramName, String paramValue, int organizationId,String getChildLst){
		int count = personnelDaoImpl.ListCount(personnel_id, personnel_name, birthday, personnel_sex,
				personnel_position, organization_name, department, paramName, paramValue, organizationId,getChildLst);
		log.info("PLAT 查询多条人员信息：count="+count+",personnel_id="+personnel_id+",personnel_name="+personnel_name+",birthday="+birthday
				+ ",personnel_sex="+personnel_sex+",personnel_position="+personnel_position+",organization_name="+organization_name+",department="+department
				+ ",paramName="+paramName+",paramValue="+paramValue);
		return count;
	}
	
	public Personnel query1(int organization_id){
		Personnel personnel = personnelDaoImpl.query1(organization_id);
		log.info("PLAT: 查询人员信息: ");
		return personnel;
	}
	/**
	 * 
	 * @param personnel_id
	 * @return
	 */
	public Personnel query(int personnel_id){
		Personnel personnel = personnelDaoImpl.query(personnel_id);
    	log.info("PLAT: 查询人员信息: "+personnel.getPersonnel_id());
    	return personnel;
	}
	
	/**
	 * 
	 * @param personnel
	 * @return
	 */
	public void add(Personnel personnel){
		personnelDaoImpl.add(personnel);
		log.info("PLAT: 添加查询人员信息: "+personnel.getPersonnel_name());
	}
	
	/**
	 * 
	 * @param personnel
	 * @return
	 */
	public boolean edit(Personnel personnel){
		boolean bl=false;
		bl=personnelDaoImpl.edit(personnel);
		log.info("PLAT: 修改查询人员信息: "+personnel.getPersonnel_id());
		return bl;
	}
	
	/**
	 * 
	 * @param personnel_id
	 * @return
	 */
	public void delete(int personnel_id){
		//删除对应账号
		if(personnelDaoImpl.query(personnel_id).getAccount_id()!=0){
			int accountId=personnelDaoImpl.query(personnel_id).getAccount_id();
			sysManagerDaoImpl.deleteManager(accountId);
		}
		personnelDaoImpl.delete(personnel_id);
		//删除对应账号
		
		log.info("PLAT: 删除人员信息: personnel_id="+personnel_id);
	}
	public void deleteById(int organization_id){
		//删除对应账号
		List<Personnel> perList=personnelDaoImpl.queryList(0, null, null, null, null, null, null, null, null, null, 0, 1000000, organization_id,null);
		for(Personnel per : perList){
			if(per.getAccount_id()!=0){
				int accountId=per.getAccount_id();
				sysManagerDaoImpl.deleteManager(accountId);
			}
		}
		personnelDaoImpl.deleteById(organization_id);
		log.info("PLAT: 删除人员信息: organization_id="+organization_id);
	}
}